#include "RegisterValidator.h"
#include "Network/Manager.h"


namespace TC
{
    namespace Request
    {

        void RegisterValidator::usernameExist(const QString &username)
        {
            if (status() == Status::Communicating)
                return;
            AbstractRemoteProcedure::get("user/usernameExist",
            {
                { "username", username }
            });
        }

        void RegisterValidator::emailExist(const QString &email)
        {
            if (status() == Status::Communicating)
                return;

            AbstractRemoteProcedure::get("user/emailExist",
            {
                { "email", email }
            });
        }

        void RegisterValidator::phoneExist(const QString &phone)
        {
            if (status() == Status::Communicating)
                return;
            AbstractRemoteProcedure::get("user/phoneExist",
            {
                { "phone", phone }
            });
        }

        void RegisterValidator::onDataReady(QDataStream &stream)
        {
            bool result;
            stream >> result;
            if (!result)
                setOk();
            else
                setFailed();
        }
    }
}